//
//  MBProgressHUD+DFHUD.m
//  WOQIEarjoy
//
//  Created by 孙鹏飞 on 2023/11/6.
//

#import <UIKit/UIKit.h>
#import <BIToolModule/NSObject+ViewController.h>

#import "MBProgressHUD+DFHUD.h"

const NSInteger hideTime = 2;

@implementation MBProgressHUD (DFHUD)

#pragma mark-------------------- show Tip----------------------------

+ (void)showTipMessageInWindow:(NSString*)message{
    [self showTipMessage:message isWindow:true timer:hideTime];
}
+ (void)showTipMessageInView:(NSString*)message{
    [self showTipMessage:message isWindow:false timer:hideTime];
}
+ (void)showTipMessageInWindow:(NSString*)message timer:(float)aTimer{
    [self showTipMessage:message isWindow:true timer:aTimer];
}
+ (void)showTipMessageInView:(NSString*)message timer:(float)aTimer{
    [self showTipMessage:message isWindow:false timer:aTimer];
}
+ (void)showTipMessage:(NSString*)message isWindow:(BOOL)isWindow timer:(int)aTimer{
    MBProgressHUD *hud = [self createMBProgressHUDviewWithMessage:message isWindiw:isWindow];
    hud.mode = MBProgressHUDModeText;
    [hud hideAnimated:YES afterDelay:hideTime];
}
#pragma mark-------------------- show Activity----------------------------

+ (void)showActivityMessageInWindow:(NSString*)message{
    [self showActivityMessage:message isWindow:true timer:0];
}
+ (void)showActivityMessageInView:(NSString*)message{
    [self showActivityMessage:message isWindow:false timer:0];
}
+ (void)showActivityMessageInWindow:(NSString*)message timer:(float)aTimer{
    [self showActivityMessage:message isWindow:true timer:aTimer];
}
+ (void)showActivityMessageInView:(NSString*)message timer:(float)aTimer{
    [self showActivityMessage:message isWindow:false timer:aTimer];
}
+ (void)showActivityMessage:(NSString*)message isWindow:(BOOL)isWindow timer:(int)aTimer{
    MBProgressHUD *hud  =  [self createMBProgressHUDviewWithMessage:message isWindiw:isWindow];
    hud.mode = MBProgressHUDModeIndeterminate; ////菊花样式，默认值
    if (aTimer>0) {
        [hud hideAnimated:YES afterDelay:aTimer];
    }
}
#pragma mark-------------------- show Image----------------------------

+ (void)showSuccessMessage:(NSString *)Message{
    [self showCustomIconInView:@"MBHUD_Success" message:Message];
}
+ (void)showErrorMessage:(NSString *)Message{
    [self showCustomIconInView:@"MBHUD_Error" message:Message];
}
+ (void)showCustomIconInWindow:(NSString *)iconName message:(NSString *)message{
    [self showCustomIcon:iconName message:message isWindow:true];
}
+ (void)showCustomIconInView:(NSString *)iconName message:(NSString *)message{
    [self showCustomIcon:iconName message:message isWindow:false];
}
+ (void)showCustomIcon:(NSString *)iconName message:(NSString *)message isWindow:(BOOL)isWindow{
    MBProgressHUD *hud  =  [self createMBProgressHUDviewWithMessage:message isWindiw:isWindow];
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:iconName]];
    hud.mode = MBProgressHUDModeCustomView;
    [hud hideAnimated:YES afterDelay:hideTime];
}
+ (MBProgressHUD*)createMBProgressHUDviewWithMessage:(NSString*)message isWindiw:(BOOL)isWindow{
    UIView  *view = isWindow? (UIView*)[UIApplication sharedApplication].delegate.window : [self currentVC].view;
    if (!view) {
        return [MBProgressHUD new];
    }
    MBProgressHUD * hud = [MBProgressHUD HUDForView:view];
    if (!hud) {
        hud =[MBProgressHUD showHUDAddedTo:view animated:YES];
    }else{
        [hud showAnimated:YES];
    }
    hud.minSize = CGSizeMake(100, 0);             //背景框的最小大小
    hud.margin = 10;                              //设置各个元素距离矩形边框的距离，可以根据这个设置提示框的大小
    hud.offset = CGPointMake(0.f, 0);             //设置提示框相对于父视图中心点的偏移值 中心点位于页面中心点
    hud.contentColor = [UIColor whiteColor];               //提示语颜色
    hud.bezelView.color = [UIColor blackColor];              //提示框背景色
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;  //纯色背景
    hud.removeFromSuperViewOnHide = YES;          //当隐藏时，从父视图中移除HUD
    hud.label.text = message?message:@"加载中...";
    hud.label.font = [UIFont systemFontOfSize:15];
    hud.label.numberOfLines = 0;
//    hud.bezelView.layer.cornerRadius = 20.0;      //设置背景框圆角
//    hud.backgroundColor = KRedColor;
    return hud;
}

+ (void)hideHUD{
    UIView  *winView =(UIView*)[UIApplication sharedApplication].delegate.window;
    [self hideHUDForView:winView animated:YES];
//    [self hideAllHUDsForView:[kAppDelegate getCurrentUIVC].view animated:YES];
}

@end
